package com.steak.bootactivemq.service.impl;

import com.steak.bootactivemq.mapper.CommodityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Service;

import javax.jms.JMSException;
import javax.jms.TextMessage;

@Service
public class CommodityServiceImpl {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    private CommodityMapper commodityMapper;

    @JmsListener(destination = "${myQueue}")
    public void reduceStock(TextMessage textMessage) throws JMSException {
        String id = textMessage.getText();
        commodityMapper.reduceStock(id);
        System.out.println("-----------------------------减库存");
    }
}
